<?php

function vtcalc( $param ){
	global $vt;

	$param = compileParameter( $param );
	if( $param ){
		ob_start();
		eval( '$result = ' . $param . ';' );
		$vt['result'] = $result;
		ob_end_clean();
	} else {
		$vt['result'] = '';
	}
}

function vtif_test( $param ){
	global $vt;

	$param = compileParameter( $param );
	if( $param ){
		ob_start();
		eval( '$result = ' . $param . ';' );
		ob_end_clean();
	} else {
		$result = false;
	}
	
	return $result;
}

function vtrepeat_init( $param ){
	global $vt;

	$param = compileParameter( $param );

	if( strpos( "\n", $param ) ){
		$list = explode( "\n", $param );
	} else if( strpos( '|', $param ) ){
		$list = explode( '|', $param );
	} else {
		$list = explode( ',', $param );
	}

	if( !isset( $vt['repeat'] ) ){
		$vt['repeat'][] = $list;
	} else {
		array_unshift( $vt['repeat'], $list );
	}
	
	reset( $vt['repeat'][0] );
}

function vtset( $param ){
	global $vt;

	$setparams = tecler::parseParameters( $param );
	if( is_array( $setparams ) ) {
		foreach( $setparams as $key => $value ) {
			$name = compileParameter($key);
			$vt['set'][$name] = compileParameter($value);
		}
	} else {
		$name = compileParameter( $setparams );
		$vt['set'][$name] = $vt['result'];
	}
}

function compileParameter( $name ){
	global $vt;

	if( strpos( $name, '{' ) !== false ){
		$c = new vtcompiler;
		$c->tagStart = '{';
		$c->tagEnd = '}';
		$c->registerLibrary( new vtcompiler_additions );
		$result = $c->parseString( $name );
		ob_start();
		eval( $result );
		$output = ob_get_contents();
		ob_end_clean();
	} else {
		$output = $name;
	}
	return $output;
}

?>